if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_HangHoa_GetHangHoaTonKhoOfChiNhanhByMaChiNhanh]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_HangHoa_GetHangHoaTonKhoOfChiNhanhByMaChiNhanh]
GO
CREATE PROCEDURE [sp_HangHoa_GetHangHoaTonKhoOfChiNhanhByMaChiNhanh]
		@Ma_chi_nhanh		int
AS
BEGIN
	SELECT
		(CONVERT(varchar(40),E.ID) +' - '+ E.Ten) AS 'Ma_ten_hang',
		A.Gia_xuat_cuoi,
		A.So_luong AS 'So_luong_ton',
		E.Ma_don_vi_qui_doi,
		E.ID AS 'Ma_hang_hoa',
		E.Ten AS 'Ten_hang_hoa',
		E.Ton_dinh_muc,
		E.Barcode_new AS 'Barcode',
		E.Thue AS 'VAT',
		E.Chiet_khau,
		A.Ma_loai_hang_ton,
		B.Ten AS 'Ten_hang_ton',
		A.Gia_nhap_cuoi,
		A.Gia_xuat_cuoi,
		C.ID AS 'Ma_kho_hang',
		C.Ten AS 'Ten_kho_hang',
		C.Ma_chi_nhanh,
		D.ID AS 'Ma_loai_kho_hang',
		D.Ten AS 'Ten_loai_kho_hang'
	FROM HangTon AS A
	INNER JOIN LoaiHangTon AS B		 ON A.Ma_loai_hang_ton = B.ID 
	INNER JOIN KhoHang AS C			 ON A.Ma_kho_hang = C.ID
	INNER JOIN LoaiKhoHang AS D		 ON C.Ma_loai_kho_hang = D.ID
	INNER JOIN HangHoa AS E			 ON A.Ma_hang = E.ID
	WHERE C.Ma_chi_nhanh = @Ma_chi_nhanh
END

